home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / ispell40.lha / ispell-4.0 / case.c < prev    next >
C/C++ Source or Header  |  1993-04-15  |  2KB  |  90 lines

  1. /* Copyright (C) 1990, 1993 Free Software Foundation, Inc.
  2.  
  3.    This file is part of GNU ISPELL.
  4.  
  5.    This program is free software; you can redistribute it and/or modify
  6.    it under the terms of the GNU General Public License as published by
  7.    the Free Software Foundation; either version 2, or (at your option)
  8.    any later version.
  9.  
  10.    This program is distributed in the hope that it will be useful,
  11.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.    GNU General Public License for more details.
  14.  
  15.    You should have received a copy of the GNU General Public License
  16.    along with this program; if not, write to the Free Software
  17.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  18.  
  19. #include <stdio.h>
  20. #ifdef MSDOS
  21. #include <stdlib.h>
  22. #include <io.h>
  23. #endif
  24. #include <fcntl.h>
  25. #include <ctype.h>
  26. #include "ispell.h"
  27. #include "hash.h"
  28. #include "good.h"
  29.  
  30. #ifndef _toupper
  31. #define _toupper toupper
  32. #endif
  33. #ifndef _tolower
  34. #define _tolower tolower
  35. #endif
  36.  
  37. void
  38. fixcase (word, c)
  39.   char *word;
  40.   struct sp_corrections *c;
  41. {
  42.   int i;
  43.   int rest_case;
  44.   int first_case;
  45.   char *p;
  46.  
  47.   if (isupper (word[0]))
  48.     {
  49.       first_case = 1;
  50.       if (isupper (word[1]))
  51.     rest_case = 1;
  52.       else
  53.     rest_case = 0;
  54.     }
  55.   else
  56.     {
  57.       first_case = 0;
  58.       rest_case = 0;
  59.     }
  60.   for (i = 0; i < c->nwords; i++)
  61.     {
  62.       p = c->posbuf[i];
  63.       if (first_case)
  64.     {
  65.       if (islower (*p))
  66.         *p = toupper (*p);
  67.     }
  68.       else
  69.     {
  70.       if (isupper (*p))
  71.         *p = tolower (*p);
  72.     }
  73.       p++;
  74.       while (*p)
  75.     {
  76.       if (rest_case)
  77.         {
  78.           if (islower (*p))
  79.         *p = toupper (*p);
  80.         }
  81.       else
  82.         {
  83.           if (isupper (*p))
  84.         *p = tolower (*p);
  85.         }
  86.       p++;
  87.     }
  88.     }
  89. }
  90.